﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using DAL;
using NLog;
using Entities;

namespace QLTTTH
{
    public partial class frmThongTinGiaoVien : DevExpress.XtraEditors.XtraForm
    {
        public frmThongTinGiaoVien()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Focus();
            this.Close();
        }

        public void HienThi_Control(GiaoVien gv)
        {
            this.txtChuyenMon.Text = gv.ChuyenMon;
        }
        public void ThietLapThongTin(NguoiDung ng)
        {
            this.txtHoTen.Text = ng.HoTen;
            this.txtChucVu.Text = ng.ChucVu;
            this.txtMaGiaoVien.Text = ng.MaNV.ToString();
            this.dtNgaySinh.EditValue = ng.NgaySinh.ToShortDateString();
            this.txtSDT.Text = ng.SoDT;
            this.txtMail.Text = ng.Email;
            this.txtDiaChi.Text = ng.DiaChi;
            this.txtTrangThai.Text = ng.TrangThai;
            if (ng.GioiTinh.Equals("Nam"))
            {

                this.rdoGioiTinh.SelectedIndex = 0;
            }
            else
                this.rdoGioiTinh.SelectedIndex = 1;
            this.txtUsername.Text = ng.Username;
            this.txtPassword.Text = ng.Password;
            this.loupNhom.EditValue = ng.MaNhomND;
        }

        private void btnXoaTrang_DoubleClick(object sender, EventArgs e)
        {
            //this.txtChucVu.Text = "";
            //this.txtChuyenMon.Text = "";
            //this.txtDiaChi.Text = "";
            //this.txtHoTen.Text = "";
            //this.txtMaGiaoVien.Text = "";
            //this.txtMail.Text = "";
            //this.txtSDT.Text = "";
            //this.txtTrangThai.Text = "";
            //this.txtMaNhom.Text = "";
            //this.txtPassword.Text = "";
            //this.txtUsername.Text = "";
        }

        private void btnXoaTrang_Click(object sender, EventArgs e)
        {
            this.txtChucVu.Text = "";
            this.txtChuyenMon.Text = "";
            this.txtDiaChi.Text = "";
            this.txtHoTen.Text = "";
            this.txtMaGiaoVien.Text = "";
            this.txtMail.Text = "";
            this.txtSDT.Text = "";
            this.txtTrangThai.Text = "";
            this.dtNgaySinh.EditValue = DateTime.Now;
            rdoGioiTinh.SelectedIndex = 0;
            this.loupNhom.ResetText() ;
            this.txtPassword.Text = "";
            this.txtUsername.Text = "";
        }

        private void frmThongTinGiaoVien_Load(object sender, EventArgs e)
        {
            this.txtPassword.Properties.UseSystemPasswordChar = true;

            var dsNhom = NhomNguoiDungManager.LayDanhSachNhomNguoiDung();
            if (dsNhom.Success)
            {
                loupNhom.Properties.DataSource = dsNhom.Result;
                loupNhom.Properties.ValueMember = "MaNhomND";
                loupNhom.Properties.DisplayMember = "TenNhom";
                if (loupNhom.ItemIndex < 0)
                {
                    loupNhom.ItemIndex = 0;
                }
            }
        }


        public delegate void SendData(GiaoVienInfo gv);

        public SendData sendData;

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (sendData != null)
            {
                sendData(GetGiaoVien());
            }
            this.Close();
        }
        public GiaoVienInfo GetGiaoVien()
        {
            var gv = new GiaoVienInfo();
            if (!txtMaGiaoVien.Text.ToString().Equals(""))
            {
                gv.MaNV = int.Parse(txtMaGiaoVien.Text.ToString());
            }
            gv.ChuyenMon = txtChuyenMon.Text;
            gv.HoTen = txtHoTen.Text;
            gv.MaNhom = int.Parse(loupNhom.EditValue.ToString());
            gv.NgaySinh = DateTime.Parse(dtNgaySinh.Text);
            if (rdoGioiTinh.SelectedIndex == 0)
                gv.GioiTinh = "Nam";
            else
                gv.GioiTinh = "Nữ";
            gv.Password = txtPassword.Text;
            gv.Username = txtUsername.Text;
            gv.TrangThai = txtTrangThai.Text;
            gv.SoDT = txtSDT.Text;
            gv.Email = txtMail.Text;
            gv.DiaChi = txtDiaChi.Text;
            gv.ChucVu = txtChucVu.Text;
            return gv;
        }

    }
}
